package com.axsoft.jobimp.types;

public class OctaWord extends DataType {

	private long[] mValue;
	
	public final long[] getValue() {
		return mValue;
	}
	
	public OctaWord(final byte[] pData) {
		super(16);
		
		if (pData.length != 8) {
			return; // TODO: Throw exception!
		}
		
		mValue = new long[2];
		
		// TODO: Refactor this motherfucking shit!
		mValue[0] = mValue[1] = 0;
		
		mValue[0] |= pData[0] & 0xFF;
		mValue[0] <<= 8;
		mValue[0] |= pData[1] & 0xFF;
		mValue[0] <<= 8;
		mValue[0] |= pData[2] & 0xFF;
		mValue[0] <<= 8;
		mValue[0] |= pData[3] & 0xFF;	
		mValue[0] <<= 8;
		mValue[0] |= pData[4] & 0xFF;
		mValue[0] <<= 8;
		mValue[0] |= pData[5] & 0xFF;
		mValue[0] <<= 8;
		mValue[0] |= pData[6] & 0xFF;
		mValue[0] <<= 8;
		mValue[0] |= pData[7] & 0xFF;
		
		mValue[1] |= pData[4] & 0xFF;
		mValue[1] <<= 8;
		mValue[1] |= pData[5] & 0xFF;
		mValue[1] <<= 8;
		mValue[1] |= pData[6] & 0xFF;
		mValue[1] <<= 8;
		mValue[1] |= pData[7] & 0xFF;
		mValue[1] <<= 8;
		mValue[1] |= pData[8] & 0xFF;
		mValue[1] <<= 8;
		mValue[1] |= pData[9] & 0xFF;
		mValue[1] <<= 8;
		mValue[1] |= pData[10] & 0xFF;
		mValue[1] <<= 8;
		mValue[1] |= pData[11] & 0xFF;
		
		setData(pData);		
	}
	
	public OctaWord() {
		super(16);
		mValue = new long[2];
		mValue[0] = mValue[1] = 0x00;
	}
	
	public OctaWord(final long[] pData) {
		super(16);
		setOctaWord(pData);
	}
	
	public void setOctaWord(final long[] pData) {
		mData[0] = (byte) (pData[0] >>> 56);
		mData[1] = (byte) (pData[0] >>> 48);
		mData[2] = (byte) (pData[0] >>> 40);
		mData[3] = (byte) (pData[0] >>> 32);
		mData[4] = (byte) (pData[0] >>> 24);
		mData[5] = (byte) (pData[0] >>> 16);
		mData[6] = (byte) (pData[0] >>> 8);
		mData[7] = (byte) (pData[0]);
		
		mData[8] = (byte) (pData[1] >>> 56);
		mData[9] = (byte) (pData[1] >>> 48);
		mData[10] = (byte) (pData[1] >>> 40);
		mData[11] = (byte) (pData[1] >>> 32);
		mData[12] = (byte) (pData[1] >>> 24);
		mData[13] = (byte) (pData[1] >>> 16);
		mData[14] = (byte) (pData[1] >>> 8);
		mData[15] = (byte) (pData[1]);
		
		mValue[0] = pData[0];
		mValue[1] = pData[1];
	}
	
}
